package com.myjpa.generate;

import lombok.Getter;
import lombok.Setter;

/**
 * @author: yaoll
 * @date: 2020-09-04
 * @verison: 1.0
 */
@Getter
@Setter
public class RepositoryGenerator {

	private StringBuilder buff;

	public void generate(GenerateContext ctx) {

		GenerateContext.PrimaryKey primaryKey = ctx.getPrimaryKey();
		String keyType = primaryKey.getType();

		buff = new StringBuilder();
		buff.append("package " + ctx.getPkg() + ".repository;").append("\n");
		buff.append("").append("\n");
		buff.append("import " + ctx.getPkg() + ".entity." + ctx.getEntityClass() + ";").append("\n");
		buff.append("import org.springframework.data.jpa.repository.JpaRepository;\n");
		buff.append("import org.springframework.data.querydsl.QuerydslPredicateExecutor;\n");
		buff.append("").append("\n");
		buff.append("public interface ")
				.append(ctx.getRepositoryClass())
				.append(" extends JpaRepository<").append(ctx.getEntityClass()).append(", " + keyType + ">, ")
				.append("QuerydslPredicateExecutor<").append(ctx.getEntityClass()).append(">{")
				.append("\n");
		buff.append("}").append("\n");
		buff.append("").append("\n");
	}

}
